package com.cpe.web.controller.feedback;

import static org.springframework.web.bind.annotation.RequestMethod.POST;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cpe.data.domain.feedback.Feedback;
import com.cpe.data.domain.feedback.FeedbackForm;
import com.cpe.repository.mapper.feedback.FeedbackMapper;
import com.cpe.transfer.feedback.FeedbackTransfer;
import com.sql.data.response.CommonRespCode;
import com.sql.data.response.JsonResponse;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/feedbacks")
public class FeedbackController {

	@Resource
	private FeedbackMapper feedbackMapper;

	@Resource
	private FeedbackTransfer feedbackTransfer;

	/**
	 * 添加
	 */
	@RequestMapping(method = POST)
	public JsonResponse addFeedback(@RequestBody FeedbackForm feedbackForm) {
		if (feedbackForm.stopCreate()) {
			return JsonResponse.invalid("缺少必输项！");
		}
		try {
			Feedback feedback = feedbackTransfer.toEntity(feedbackForm);
			feedbackMapper.insert(feedback);
		} catch (Exception e) {
			log.info(e.getMessage(), e);
			return JsonResponse.custom(CommonRespCode.EXCEPTION);
		}
		return JsonResponse.ok();
	}
}
